import {Component,OnInit,ViewChild} from '@angular/core';
import { PageModel } from "../../../../model/page-model";
import { ModalDirective } from 'ng2-bootstrap/modal';
import { flyIn } from '../../../../animations/fly-in';
import { MyHttp } from '../../../../service/MyHttp';
import { HMPipe } from "../../../../pipe/hm.pipe";
@Component({
  selector: 'ordinaryorder',
  templateUrl: './ordinaryorder.component.html',
  styleUrls: ['./ordinaryorder.component.css'],
  animations: [
    flyIn
  ]
})
export class Ordinaryorder implements OnInit{
  @ViewChild('myModal') public myModal:ModalDirective;
  pageModel = new PageModel();
  page:number = 1;
  orderdata:any;
  keyWord:string = '';
  private key_word:string = '';
  constructor(private myHttp:MyHttp) {}
  ngOnInit() {   
    this.key_word = this.keyWord = localStorage.getItem('order_order_key_word')?localStorage.getItem('order_order_key_word'):'';
    this.getData(1);
  }


  getData(page){
    this.page = page;
    this.myHttp.post('order/findByPage?page='+page+'&key_word='+this.key_word,{}).subscribe(res=>{
      if(res.errorCode==0){
        for(let item of res.message.data){
          if(item.order_status == 0){
            item.order_use_real_time = new Date().getTime() - new Date(item.created_at.replace(/-/g, '/')).getTime();
            item.order_use_real_time = Math.floor(item.order_use_real_time/1000/60);
          }
        }
        this.orderdata = res.message.data;    
        this.pageModel.setPage({'iTotalRecords':res.message.total});
      }
     
    },err=>console.log(err));
  }
  search(){
    localStorage.setItem('order_order_key_word',this.keyWord);
    this.key_word = this.keyWord;
    this.getData(1);
    this.pageModel.currentPage = 1;
  }
  getSearchdata(){
      this.myHttp.post('order/findByTel',{
        "user_telephone" :this.keyWord
      }).subscribe(res=>{
      if(res.errorCode==0){
        this.orderdata = res.message; 
      }
     
    },err=>console.log(err));
  }
  


}

